import java.util.ArrayList;

/**
 * Class <code>HeuristicII</code> 
 */
public class HeuristicII implements ISuspiciousnessCalculator {

	/**
	 *Calculate the Suspiciousness of each statement 
	 * @param nnStatementCoverTable nnStatementCoverTable[i][j] is the number of test case i that execute statement j
	 * @return the Suspiciousness of each statement
	 */
	@Override
	public ArrayList<Double> calcSuspiciousness(
			ArrayList<ArrayList<Integer>> nnStatementCoverTable) {
		
		/**The Suspiciousness of each statement*/
		ArrayList<Double> darrSuspiciousness = 
			new ArrayList<Double>();
		
		for(int j = 0 ; j < nnStatementCoverTable.get(0).size()-1; j++ ){

			/**Number of failed tests that execute statement j*/
			double dTempFailure = 0.0;
			
			/**Number of successful tests that execute statement j*/
			double dTempSuccess = 0.0;
			
			for(int i = 0 ; i <nnStatementCoverTable.size() ; i++ ){
				dTempFailure +=(double) (nnStatementCoverTable.get(i).get(j)>0 ? 1 : 0) 
				 * nnStatementCoverTable.get(i).get(nnStatementCoverTable.get(i).size()-1) ;
				dTempSuccess +=(double) (nnStatementCoverTable.get(i).get(j)>0 ? 1 : 0) 
				 * ( 1 - nnStatementCoverTable.get(i).get(nnStatementCoverTable.get(i).size()-1) );
			}
			darrSuspiciousness.add(dTempFailure - dTempSuccess);
		}
		
		return darrSuspiciousness;
	}

}
